window.workspace = function(){
	var response = <?#$respons?>;
	var tables, items, vform, tbars, vdata, readoly;
	function doSubmitHandle(status, obj) {
		var dataform = obj.findParentByType('form'); 
		if(!dataform.getForm().isValid())
			return;
		dataform.getForm().submit({
    		waitMsg 	: '数据提交处理中...',
			waitTitle 	: '信息提示',
			params		: {'status': status, 'executorid':response.executor.executorid, 'workflowid':response.executor.workflowid},		
    		clientValidation: true,
    		url			: '/admin/workflow/executor/dosubmit.html',
        	success		: function(form, action) {
        		Ext.Msg.alert('信息提示', action.result.msg);
        		if(action.result.code == 0) {
        			window.setTimeout(function(){
        				window.location.href = action.result.url;
        			}, 1000);
        		}	
			},
			failure	: main.submitFailure
    	});	    	
	};
	function doSetOnly() {
		var idx = this.id;
		idx     = idx.substr(idx.lastIndexOf('-')+1);
		idx     = parseInt(idx);
		this.cascade(function(){
    		if(this.setReadOnly) {
    			this.setReadOnly(true);
    			if(this.xtype == 'combo') {
    				this.setDisabled(true);
    				var value = response.executor.nodes[idx].data[this.name];
    				if(!!value) {
    					this.setValue(value);
    					this.setRawValue(value);
    				}
    			}
    		}
    	});
	}
	
	//表单Table顶部状态导航, 单据名称栏位
	items = [{ 	
		colspan	  : 2,
		bodyStyle : 'color: #CC6633; font-size: 12px; padding:3px 0px; background-color:#ffcc00;',
		html	  : '<span style="padding: 0px 18px;" class="icon-warning icon"><b>'+response.executor.statusbar+'</b></span>'
    },{ 	
		colspan	  : 2,
		bodyStyle : 'font-size: 24px; text-align: center; height: 42px; padding-top:6px;',
		html	  : response.executor.title+((response.executor.executorid > 0)?
				'<span style="font-size:12px;padding-left:4px;">[单据号：'+response.executor.executorid+']</span>':'')
    }];
	//追加表单结点表单展示信息
	for(var idx in response.executor.nodes) {
		//其他函数附加属性直接跳过
		if(Ext.isFunction(response.executor.nodes[idx])) {
			continue; 
		}
		vdata 	= response.executor.nodes[idx];
		vform   = eval(vdata.panel);
		readoly = doSetOnly;
		if(vdata.dosubmit == 1) {
			var sbtn= eval(vdata.button);
			vform.push(sbtn[0]);
			readoly = Ext.emptyFn;
		}
		items.push({
	        html 		: vdata.tips,
	        bodyStyle	: 'padding:6px;'
	    });
		items.push({ 	 
			id			: 'ext-form-data-'+idx,
	        xtype		: 'form',
	        bodyStyle	: 'padding:8px;',
	        labelWidth	: 140,
	        labelAlign  : 'right',
	    	defaults	: {
	    		xtype	  : 'textfield',
	    		width	  : 660,
	    		msgTarget : 'side'
	    	},
	        items		: vform,
	        listeners	: {'render':readoly}
		});
	};
	//顶部导航按钮操作列表
	tbars = [{
			text	: '返回系统',
			iconCls	: 'icon-arrow-left',
			handler : function(){
				var host = (window.location.host)? window.location.host:window.location.hostname;
				window.location.href = 'http://'+host+'/admin';	
			}
		},{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
				window.location.reload();	
			}
	}];
	if(!!response.executor.isdoaccept) {
		tbars.push({
			text	: '接受任务',
			iconCls	: 'icon-unlock',
			handler : function(){
				Ext.Ajax.request({
					url		: '/admin/workflow/executor/doaccept.html',
					params 	: {'sid':response.executor.stateid},
					success : function(resp, req){
						var data = Ext.decode(resp.responseText);
						Ext.Msg.alert('消息提示', data.msg);
						if(data.code == 0) {
							setTimeout(function(){
								window.location.reload();
							}, 1000);
						}
					}
				});
			}
		});
	};
	if(!!response.executor.isdostop) {
		tbars.push({
			text	: '终止任务',
			iconCls	: 'icon-delete',
			handler : function(){
				Ext.Msg.prompt('信息提示', '终止原因', function(btn, msg) {
					if(btn == "ok") {
						msg = msg.trim();
						if(msg.length < 1) {
							Ext.Msg.alert('信息提示', '请填写终止理由！');return;
						}
						Ext.Ajax.request({
							url		: '/admin/workflow/executor/dostop.html',
							params 	: {'executorid':response.executor.executorid,'remark':msg},
							success : function(resp, req) {
								var data = Ext.decode(resp.responseText);
								Ext.Msg.alert('信息提示', data.msg);
								if(data.code == 0) {
									setTimeout(function(){
										window.location.reload();
									}, 1000);
								}
							}
						});
					}
				}, window, true);
			}
		});
	};
	if(response.executor.deliverid > 0) {
		tbars.push({
			text	: '任务转单',
			iconCls	: 'icon-key-add',
			handler : function(){
				if(!response.deliverwin) {
					var deliverform = new Ext.form.FormPanel({
						frame		: true,
						border		: false,
						bodyStyle	: 'padding:8px;',
		        		labelWidth	: 80,
		        		labelAlign  : 'right',
		    			defaults	: {
		    				xtype	  : 'textfield',
		    				msgTarget : 'side'
		    			},
	    				items		: [{
		           	 		xtype		: 'hidden',
		            		name		: 'sid',
		            		value 		: response.executor.deliverid
		    			},{
				            xtype		: 'combo',
							width	  	: 260,
							hideOnSelect: false,
							store		: new Ext.data.JsonStore({
				            	url			: '/admin/share/douser.html',
				            	autoDestroy : true,
				            	fields		: ['id', 'name'],
				            	root		: 'dataset'
				            }),
				            name			: 'userid',
				            hiddenName		: 'userid',
							emptyText		: '可输入用户名称进行查找...',
				            fieldLabel		: '接单人信息',
				            pageSize		: 10,
				            minChars    	: 1,
				            displayField	: 'name',
							valueField		: 'id',
							triggerAction	: 'all',
							mode			: 'remote'
				    	}]
					});
					response.deliverwin = new Ext.Window({
						title		: '转单操作',
						iconCls		: 'icon-edit',
						width		: 420,
						height		: 128,		
						items		: [deliverform],
						closeAction : 'hide',
						bbar 		: {
							xtype		: 'toolbar',
							buttonAlign	: 'right',
							items		: [{
								text	: '保存', 
								iconCls	: 'icon-save',
								handler : function(){
									if(!deliverform.getForm().isValid())
				        				return;
									deliverform.getForm().submit({
						        		waitMsg 		: '数据提交处理中...',
										waitTitle 		: '信息提示',
						        		clientValidation: true,
						        		url				: '/admin/workflow/executor/dodeliver.html',
							        	success			: function(form, action) {
							        		Ext.Msg.alert('信息提示', action.result.msg);
							        		response.deliverwin.hide();
							        		setTimeout(function(){ window.location.reload();},1000)
										}
						    		});
								}
							}]
						}
					});
					window.onresize = function () {
						response.deliverwin.center();
					}
				}
				response.deliverwin.show();
			}
		});
	};
	tbars = tbars.concat(['->',{
		text	: '去当前节点',
		iconCls	: 'icon-assigned',
		handler : function(){
			var surl = window.location.href;
			window.location.href = surl.replace(/#NN$/, '')+'#NN';
		}
	},{
		text	: '流程预览',
		iconCls	: 'icon-heart',
		handler : function() {
			var url = '/admin/workflow/preview/id-xxx.html';
			window.open(url.replace('xxx', response.executor.workflowid));	
		}
	},{
		text	: '帮助',
		iconCls	: 'icon-help',
		handler : function(){
			Ext.Msg.alert('信息提示','帮助系统即将推出，请耐心等候！');
		}
	}]);
	tables = new Ext.Panel({
		region		: 'center',
		title		: '['+response.executor.title+']',
		autoScroll	: true,
		padding 	: '3px 48px 8px 58px',
		layout		: 'table',
		defaults	: {
			xtype	: 'panel',
			border	: false
		},
		layoutConfig: {
			columns 	: 2,
			tableAttrs 	: {
				style	: {
					border : 'solid 1px #000',
					width  : '100%'
				}
			}
		},
        items		: items,
        tbar		: tbars
	});
	return tables;
}();